(function () {
  var vm = window.vm = new Vue({
    el: '.aui-wrapper',
    i18n: window.SITE_CONFIG.i18n,
    mixins: [window.SITE_CONFIG.mixinViewModule],
    data: function () {
      return {
        mixinViewModuleOptions: {
          getDataListURL: '/lswms/checkdetail/page',
          getDataListIsPage: true,
          exportURL: '/lswms/checkdetail/export',
          deleteURL: '/lswms/checkdetail',
          deleteIsBatch: true
        },
        dataForm: {
          id: ''
        }
      }
    },
    components: {
      'add-or-update': fnAddOrUpdateComponent()
    },
    beforeCreate: function () {
      vm = this;
    }
  });
})();

/**
 * add-or-update组件
 */
function fnAddOrUpdateComponent () {
  var self = null;
  return {
    template: '\
      <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t(\'add\') : $t(\'update\')" :close-on-click-modal="false" :close-on-press-escape="false" :fullscreen="true">\
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()" label-width="120px">\
          <el-form-item label="盘点号" prop="checkkey">\
            <el-input v-model="dataForm.checkkey" placeholder="盘点号"></el-input>\
          </el-form-item>\
          <el-form-item label="行号" prop="line">\
            <el-input v-model="dataForm.line" placeholder="行号"></el-input>\
          </el-form-item>\
          <el-form-item label="状态" prop="status">\
            <el-input v-model="dataForm.status" placeholder="状态"></el-input>\
          </el-form-item>\
          <el-form-item label="自商品" prop="sku">\
            <el-input v-model="dataForm.sku" placeholder="自商品"></el-input>\
          </el-form-item>\
          <el-form-item label="批号" prop="lot">\
            <el-input v-model="dataForm.lot" placeholder="批号"></el-input>\
          </el-form-item>\
          <el-form-item label="库位编码" prop="location">\
            <el-input v-model="dataForm.location" placeholder="库位编码"></el-input>\
          </el-form-item>\
          <el-form-item label="目的托盘" prop="tray">\
            <el-input v-model="dataForm.tray" placeholder="目的托盘"></el-input>\
          </el-form-item>\
          <el-form-item label="目的容器" prop="box">\
            <el-input v-model="dataForm.box" placeholder="目的容器"></el-input>\
          </el-form-item>\
          <el-form-item label="数量" prop="qty">\
            <el-input v-model="dataForm.qty" placeholder="数量"></el-input>\
          </el-form-item>\
          <el-form-item label="初盘数量" prop="firstqty">\
            <el-input v-model="dataForm.firstqty" placeholder="初盘数量"></el-input>\
          </el-form-item>\
          <el-form-item label="初盘人" prop="firstuser">\
            <el-input v-model="dataForm.firstuser" placeholder="初盘人"></el-input>\
          </el-form-item>\
          <el-form-item label="初盘时间" prop="firsttime">\
            <el-input v-model="dataForm.firsttime" placeholder="初盘时间"></el-input>\
          </el-form-item>\
          <el-form-item label="复盘数量" prop="secondqty">\
            <el-input v-model="dataForm.secondqty" placeholder="复盘数量"></el-input>\
          </el-form-item>\
          <el-form-item label="复盘人" prop="seconduser">\
            <el-input v-model="dataForm.seconduser" placeholder="复盘人"></el-input>\
          </el-form-item>\
          <el-form-item label="复盘时间" prop="secondaddtime">\
            <el-input v-model="dataForm.secondaddtime" placeholder="复盘时间"></el-input>\
          </el-form-item>\
          <el-form-item label="生产日期" prop="lot1">\
            <el-input v-model="dataForm.lot1" placeholder="生产日期"></el-input>\
          </el-form-item>\
          <el-form-item label="有效日期" prop="lot2">\
            <el-input v-model="dataForm.lot2" placeholder="有效日期"></el-input>\
          </el-form-item>\
          <el-form-item label="属性3" prop="lot3">\
            <el-input v-model="dataForm.lot3" placeholder="属性3"></el-input>\
          </el-form-item>\
          <el-form-item label="属性4" prop="lot4">\
            <el-input v-model="dataForm.lot4" placeholder="属性4"></el-input>\
          </el-form-item>\
          <el-form-item label="属性5" prop="lot5">\
            <el-input v-model="dataForm.lot5" placeholder="属性5"></el-input>\
          </el-form-item>\
          <el-form-item label="属性6" prop="lot6">\
            <el-input v-model="dataForm.lot6" placeholder="属性6"></el-input>\
          </el-form-item>\
          <el-form-item label="属性7" prop="lot7">\
            <el-input v-model="dataForm.lot7" placeholder="属性7"></el-input>\
          </el-form-item>\
          <el-form-item label="属性8" prop="lot8">\
            <el-input v-model="dataForm.lot8" placeholder="属性8"></el-input>\
          </el-form-item>\
          <el-form-item label="属性9" prop="lot9">\
            <el-input v-model="dataForm.lot9" placeholder="属性9"></el-input>\
          </el-form-item>\
          <el-form-item label="属性10" prop="lot10">\
            <el-input v-model="dataForm.lot10" placeholder="属性10"></el-input>\
          </el-form-item>\
          <el-form-item label="备注" prop="remark">\
            <el-input v-model="dataForm.remark" placeholder="备注"></el-input>\
          </el-form-item>\
          <el-form-item label="回传状态" prop="backstatus">\
            <el-input v-model="dataForm.backstatus" placeholder="回传状态"></el-input>\
          </el-form-item>\
          <el-form-item label="回传时间" prop="backdate">\
            <el-input v-model="dataForm.backdate" placeholder="回传时间"></el-input>\
          </el-form-item>\
          <el-form-item label="回传结果" prop="backresult">\
            <el-input v-model="dataForm.backresult" placeholder="回传结果"></el-input>\
          </el-form-item>\
          <el-form-item label="回传码" prop="backcode">\
            <el-input v-model="dataForm.backcode" placeholder="回传码"></el-input>\
          </el-form-item>\
          <el-form-item label="仓库" prop="warehouse">\
            <el-input v-model="dataForm.warehouse" placeholder="仓库"></el-input>\
          </el-form-item>\
          <el-form-item label="创建人" prop="adduser">\
            <el-input v-model="dataForm.adduser" placeholder="创建人"></el-input>\
          </el-form-item>\
          <el-form-item label="创建时间" prop="addtime">\
            <el-input v-model="dataForm.addtime" placeholder="创建时间"></el-input>\
          </el-form-item>\
          <el-form-item label="修改人" prop="updatuser">\
            <el-input v-model="dataForm.updatuser" placeholder="修改人"></el-input>\
          </el-form-item>\
          <el-form-item label="修改时间" prop="updatetime">\
            <el-input v-model="dataForm.updatetime" placeholder="修改时间"></el-input>\
          </el-form-item>\
        </el-form>\
        <template slot="footer">\
          <el-button @click="visible = false">{{ $t(\'cancel\') }}</el-button>\
          <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t(\'confirm\') }}</el-button>\
        </template>\
      </el-dialog>\
    ',
    data: function () {
      return {
        visible: false,
        dataForm: {
          id: '',
          checkkey: '',
          line: '',
          status: '',
          sku: '',
          lot: '',
          location: '',
          tray: '',
          box: '',
          qty: '',
          firstqty: '',
          firstuser: '',
          firsttime: '',
          secondqty: '',
          seconduser: '',
          secondaddtime: '',
          lot1: '',
          lot2: '',
          lot3: '',
          lot4: '',
          lot5: '',
          lot6: '',
          lot7: '',
          lot8: '',
          lot9: '',
          lot10: '',
          remark: '',
          backstatus: '',
          backdate: '',
          backresult: '',
          backcode: '',
          warehouse: '',
          adduser: '',
          addtime: '',
          updatuser: '',
          updatetime: ''
        }
      }
    },
    computed: {
      dataRule: function () {
        return {
          checkkey: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          line: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          status: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          sku: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          location: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          tray: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          box: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          qty: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          firstqty: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          firstuser: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          firsttime: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          secondqty: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          seconduser: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          secondaddtime: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot1: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot2: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot3: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot4: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot5: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot6: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot7: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot8: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot9: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          lot10: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          remark: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          backstatus: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          backdate: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          backresult: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          backcode: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          warehouse: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          adduser: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          addtime: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          updatuser: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ],
          updatetime: [
            { required: true, message: this.$t('validate.required'), trigger: 'blur' }
          ]
        }
      }
    },
    beforeCreate: function () {
      self = this;
    },
    methods: {
      init: function () {
        self.visible = true;
        self.$nextTick(function () {
          self.$refs['dataForm'].resetFields();
          if (self.dataForm.id) {
            self.getInfo();
          }
        });
      },
      // 获取信息
      getInfo: function () {
        self.$http.get('/lswms/checkdetail/' + self.dataForm.id).then(function (res) {
          if (res.data.code !== 0) {
            return self.$message.error(res.data.msg);
          }
          self.dataForm = _.merge({}, self.dataForm, res.data.data);
        }).catch(function () {});
      },
      // 表单提交
      dataFormSubmitHandle: _.debounce(function () {
        self.$refs['dataForm'].validate(function (valid) {
          if (!valid) {
            return false;
          }
          self.$http[!self.dataForm.id ? 'post' : 'put']('/lswms/checkdetail', self.dataForm).then(function (res) {
            if (res.data.code !== 0) {
              return self.$message.error(res.data.msg);
            }
            self.$message({
              message: self.$t('prompt.success'),
              type: 'success',
              duration: 500,
              onClose: function () {
                self.visible = false;
                self.$emit('refresh-data-list');
              }
            });
          }).catch(function () {});
        });
      }, 1000, { 'leading': true, 'trailing': false })
    }
  }
};